import okhttp3.Call;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.junit.jupiter.api.Test;

import java.io.IOException;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;

public class ApiTest {
    @Test
    public void whenGetRequest_thenCorrect() throws IOException {
        String BASE_URL = "http://www.baidu.com";
        Request request = new Request.Builder()
                .url(BASE_URL + "/")
                .header("token", "qweqweasd123123123")
                .build();
        OkHttpClient client = new OkHttpClient();
        Call call = client.newCall(request);
        Response response = call.execute();

        assertThat(response.code(), equalTo(200));
        if (response.isSuccessful()) {
            String responseBody = response.body().string();
            System.out.println(responseBody);
        } else {
            System.out.println("请求失败，错误码：" + response.code());
        }
    }



}
